package com.my.chapter8;

import java.util.Random;

public class practice8 {
    private static RandomInstrumentGenerator gen = new RandomInstrumentGenerator();
    public static void tuneAll(Instrument2[] e){
        for(Instrument2 i:e){
            i.play();
        }
    }
    public static void main(String[] args) {
        Instrument2[] e =new Instrument2[7];
        for(int i=0;i<e.length;i++){
            e[i] = gen.next();
        }
        tuneAll(e);
    }
}

class Instrument2{
    void play(){
        System.out.println("Instrument.play()");
    }
    String what(){
        return "Instrument";
    }
    void adjust(){
        System.out.println("Adjusting Instrument");
    }
}

class Wind2 extends Instrument2{
    void play(){
        System.out.println("Wind.play()");
    }
    String what(){
        return "Wind";
    }
    void adjust(){
        System.out.println("Adjusting Wind");
    }
}

class Percussion2 extends Instrument2{
    void play(){
        System.out.println("Percussion.play()");
    }
    String what(){
        return "Percussion";
    }
    void adjust(){
        System.out.println("Adjusting Percussion");
    }
}

class Stringed2 extends Instrument2{
    void play(){
        System.out.println("Stringed.play()");
    }
    String what(){
        return "Stringed";
    }
    void adjust(){
        System.out.println("Adjusting Stringed");
    }
}

class Brass2 extends Instrument2{
    void play(){
        System.out.println("Brass.play()");
    }
    void adjust(){
        System.out.println("Adjusting Brass");
    }
}

class Guitar2 extends Instrument2{
    void play(){
        System.out.println("Guitar.play()");
    }
    String what(){
        return "Guitar";
    }
    void adjust(){
        System.out.println("Adjusting Guitar");
    }
}

class Woodwind2 extends Wind2{
    void play(){
        System.out.println("Woodwind.play()");
    }
    String what(){
        return "Woodwind";
    }
}

class RandomInstrumentGenerator{
    private Random rand = new Random(47);
    public Instrument2 next(){
        switch (rand.nextInt(7)){
            default:
            case 0:return new Instrument2();
            case 1:return new Wind2();
            case 2:return new Percussion2();
            case 3:return new Stringed2();
            case 4:return new Brass2();
            case 5:return new Guitar2();
            case 6:return new Woodwind2();
        }
    }
}
